<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    *{
    margin: 0;
    padding: 0;
    }
    /* margin:auto 水平居中 */
    .father{
        width: 400px;
        height: 400px;
        border: 1px solid;
        position: relative;
    }
    .son{
        position: absolute;
        width: 200px;
        height: 200px;
        background-color: red;
        top:0;
        right: 0;
        bottom: 0;
        left: 0;
        margin: auto;
    }
    /* transform垂直居中 */
        /* .father{
        width: 400px;
        height: 400px;
        border: 1px solid;
        position: relative;
    }
    .son{
        position: absolute;
        width: 200px;
        height: 200px;
        background-color: rgb(26, 58, 243);
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        margin: auto;
    } */
    /* flex布局 */
    /* .father{
        height: 400px;
        width: 400px;
        display: flex;
        justify-content: center;
        align-items: center;
        border: 1px solid;

    }
    .son{
        width: 200px;
        height: 200px;
        background-color: rgb(26, 243, 225);
    }  */
    /* grid布局 */
    /* .father{
        height: 400px;
        width: 400px;
        display: grid;
        justify-content: center;
        align-items: center;
        border: 1px solid;

    }
    .son{
        width: 200px;
        height: 200px;
        background-color: rgb(221, 243, 26);
    } */
</style>
<body>
    <div class="father">
        <div class="son"></div>
    </div>
</body>
</html>